#! /usr/bin/env python
import os
import waf_dynamo
from BuildUtility import create_build_utility

def configure(conf):
    build_util = create_build_utility(conf.env)
    target = build_util.get_target_os()
    if not target in ('win32', 'macos', 'linux'):
      return
    if 'macos' == target:
        conf.env.append_value('LINKFLAGS', ['-framework', 'Cocoa'])
    if 'win32' in target:
        conf.find_program('signtool', var='SIGNTOOL', mandatory = True, path_list = search_path)

def build(bld):
    build_util = create_build_utility(bld.env)
    target = build_util.get_target_os()

    exe = bld.program(features  = 'c cxx',
                       includes = ['.'],
                       use      = 'DLIB PROFILE_NULL',
                       source   = ['launcher.cpp', 'launcher_util.cpp'],
                       target   = 'launcher')

    if 'macos' == target:
        exe.source.append('macos_events.mm')

    lib = bld.stlib(features = 'cxx',
                    includes = ['.'],
                    target   = 'launcherutil',
                    source   = ['launcher_util.cpp'])

    if 'win32' in bld.env.BUILD_PLATFORM:
        exe.linkflags = ['/subsystem:windows', '/entry:mainCRTStartup']
        exe.source.append('launcher.rc')

        if waf_dynamo.authenticode_certificate_installed(bld):
            exe.features.append('authenticode')
            exe.install_path = None
            bld.install_as("${PREFIX}/bin/${PLATFORM}/launcher.exe", "launcher_signed.exe")

    bld.recurse('test')
